<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"
          name="viewport">
    <meta content="yes" name="apple-mobile-web-app-capable"/>
    <meta content="black" name="apple-mobile-web-app-status-bar-style"/>
    <meta content="telephone=no" name="format-detection"/>
    <meta name="csrf-token" content="cPqshWzq8AP6CPB3WnTjWi7etMHthoseg6rFAYVE">
    <title>确认订单</title>
    <meta name="description" content="确认订单"/>
    <meta name="Keywords" content="确认订单"/>
    {include file="common/link" /}
    <style>
        .reward_text {
            text-align: right;
            padding-right: 15px;
        }
        .p {
            width: 100px;
            height: 100px;
            margin-right: 10px;
            margin-left: 8px;
        }
        .p-pic {
            width: 100px;
            height: 100px;
        }
    </style>
</head>
<body class="body-1">
<script>
    var datas = [];
    function handledatas(id,value) {
        var state = 0;
        for (var i =0;i<datas.length;i++){
            if(datas[i]['id'] == id){
                state = 1;
                datas[i]['ht_price'] = value
            }
        }
        if(state == 0){
            datas.push({id:id, ht_price:value})
        }
    }
</script>
<div id="container">
    <div class="mui-bar-tab cart-btn-box centerflex line-top">
        <div class="total-price box-flex-1 text-l">
            <p>共<em class="selectedNum" >{$allnum}</em>件商品</p>
            <p class="total">合计：<span class="red pro-price" >0.00</span>元</p>
        </div>
        <a class="qujiesuan" href="javascript:;" >生成销售单</a>
    </div>
     
     <div class="mui-content">
<!--         <div class="receiving-address bgcolor-white mb10 arrow">-->
         <div class="receiving-address bgcolor-white" style="border-radius:15px;">
             <a href="javascript:void (0)" class="highlight  select_adr">
<!--                 <div class="p">-->
<!--                     <a href="#" title="">-->
<!--                         <img class="p-pic" src="" style="visibility: visible;">-->
<!--                     </a>-->
<!--                 </div>-->
                <h2 class="ft14 clearfix updateinfo">
                    <span class="fl">{$row.company}-    <span class="contacts">{$row.contacts}</span></span>
                    <span class="fr mobile">{$row.mobile}</span>
                </h2>
                <p class="ft13 address">
                    {$row.address}
<!--                    收货地址：{$row.address}-->
                 </p>
             </a>
         </div>
<!--         <div class="home-link-box bgcolor-white">-->
<!--             <a href="javascript:;">-->
<!--                 <i class="iconfont icon-shop"></i>-->
<!--            </a>-->
<!--         </div>-->
         <div style="margin-top: 3px;" class="showdata">
                {volist name="list" id="vo"}
             <script>
                 handledatas("{$vo.id}","{$vo.price}")
             </script>
                   <div class="order-pro-group bgcolor-white showinfo catid{$vo.id}">
                       <div class="order-pro-item  centerflex line-top"><!---->
                           <div class="txt box-flex-1 setprice" data-id="{$vo.id}">
                               <h2 class="title">{$vo.title}</h2>
<!--                               <span class="red-price">¥<em class="pro-price">110.00</em></span>-->
                               <p class="clearfix">
                                   <span class="attribute fl"><em>规格：{$vo.specs}</em></span>
                                   <span class="num fr">×<em class="ft14 goods_num">{$vo.num}</em></span>
                               </p>
                               <p>含税单价: <span class="ht_price" style="color: red">{$vo.price}</span>
<!--                                   税点: <span class="tax" style="color: red">0</span>-->
                               </p>
<!--                               <p></p>-->
<!--                               <p>数量: <span class="goods_num">0</span></p>-->
<!--                               <input type="text" placeholder="含税价格">-->
<!--                               <input type="text" placeholder="税点">-->
<!--                               <input type="text" placeholder="数量">-->
                           </div>
                       </div>
                   </div>
                {/volist}
         </div>
         <div class="settlement-item centerflex bgcolor-white line-top">
             <label>税点</label>
             <input type="text" placeholder="在此输入税点" class="box-flex-1 tax" value="{$tax}" onkeyup="checkTaxFloat(this);" disabled>
         </div>
<!--         <div class="settlement-item centerflex bgcolor-white line-top">-->
<!--             <label>运费</label>-->
<!--             <span class="red-price box-flex-1 reward_text"><em>免运费</em></span>-->
<!--         </div>-->
         <div class="settlement-item centerflex bgcolor-white line-top">
             <label>小计</label>
             <span class="red-price box-flex-1 reward_text">¥<em class="pro-price">0</em></span>
         </div>
         <div class="settlement-item centerflex bgcolor-white line-top">
             <label>备注说明</label>
             <input type="text" placeholder="在此输入备注说明" class="box-flex-1 explain">
         </div>

         <div class="weui-cells weui-cells_form">
<!--             <div class="weui-cell weui-cell_switch">-->
<!--                 <div class="weui-cell__bd">是否自动请购</div>-->
<!--                 <div class="weui-cell__ft">-->
<!--                     <input class="weui-switch is_buy" type="checkbox" value="1">-->
<!--                 </div>-->
<!--             </div>-->
<!--             <div class="weui-cell weui-cell_switch">-->
<!--                 <div class="weui-cell__bd">是否存为草稿</div>-->
<!--                 <div class="weui-cell__ft">-->
<!--                     <label for="switchCP" class="weui-switch-cp">-->
<!--                         <input id="switchCP" class="weui-switch-cp__input is_draft" type="checkbox" checked="checked" value="1">-->
<!--                         <div class="weui-switch-cp__box"></div>-->
<!--                     </label>-->
<!--                 </div>-->
<!--             </div>-->
         </div>
     </div>
{include file="common/left-nav" /}
{include file="common/script" /}
    <script src="__CDN__/assets/web/plugins/fastclick.js"></script>
<script src="__CDN__/assets/web/js/place.js"></script>
<!--<script src="__CDN__/assets/web/js/city.data3.js"></script>-->
<!--<script src="__CDN__/assets/web/plugins/mui.picker.min.js"></script>-->
<!--<script src="__CDN__/assets/web/plugins/mui.poppicker.js"></script>-->

</body>
</html>
<script>
    count()
    var cart_ids = "{$cart_ids}"
    cart_ids = cart_ids.split('-')
    var crow = [];

    var all_price = [];
    var that;
    $('.mui-content').on('click','.setprice',function () {
        layer.prompt({
            title: '设置金额',
//                    area: ['800px', '350px'] //自定义文本域宽高
        }, function(value, index, elem){
            var id = that.data('id')
            var reg = /^\d+(?=\.{0,1}\d+$|$)/
            if(!reg.test(value)) {
                layer.msg('非法参数')
                return false ;
            }
            if(value>0) {
                handledatas(id,value)
                count()
                that.find('.ht_price').html(value)
                layer.close(index);
            }else{
                layer.msg('请正确填写金额')
                return;
            }
        });
        that = $(this)
    })

    function count(){
        var price = 0;
        for (var i =0;i<datas.length;i++){
            var tnum = $('.catid'+datas[i]['id']).find('.goods_num').html()
            price = price*1+ 1*tnum*datas[i]['ht_price']
        }

        $('.pro-price').html(price.toFixed(2))
    }
    $('.qujiesuan').click(function () {
        var len = $('.showdata').children('.showinfo').length;
        if(len -1 > datas.length){
            layer.msg('商品价格必须填写')
            return  false
        }
        var tax = $('.tax').val()

        if(tax <0 || tax ==''){
            layer.msg('税点必须填写')
            $('.tax').focus()
            return false
        }
        var explain = $('.explain').val()
        var c_id = "{$c_id}"
        if(c_id <=1){
            layer.msg('未选择客户')
            return false
        }

       if(datas.length < cart_ids.length){
           layer.msg('数据不全')
           return false
       }
       // console.log(crow)
       //is_buy:$('.is_buy').prop('checked')?1:0,
        var url = "{$turl}"+'/web/sales/confirm'
        $.post(url,{datas:datas,tax:tax,explain:explain,c_id:c_id,cart_ids:cart_ids,crow:crow},function (res) {
            layer.msg(res.msg)
            if(res.code == 1){
                setInterval(function () {
                    window.location.href = '/web/sales/index'
                },800)

            }
        })

    })
    function checkTaxFloat(obj) {
        obj.value = obj.value.replace(/[^\d.]/g,"");  //清除“数字”和“.”以外的字符
        obj.value = obj.value.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的
        obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
        obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');//只能输入两个小数
        if(obj.value >13){
            obj.value = 13;
        }
        var x = obj.value.indexOf('.') + 1;   //小数点的位置
        var y = obj.value.length;

        if(x>1 && (y-x) >0){
            if((y-x)>1){
                obj.value= parseFloat(obj.value).toFixed(1)
            }
        }
        if(obj.value.indexOf(".")< 0 && obj.value !=""){
            obj.value= parseFloat(obj.value)
        }
        console.log(obj.value)



    }

    $('.updateinfo').click(function () {
        layer.prompt({
            formType: 2,
            placeholder: '客户信息',
            title: '请输入值',
                   // area: ['800px', '350px'] //自定义文本域宽高
        }, function(value, index, elem){
            crow[0] = {address:value,mobile:$('#zxr2').val(),contacts:$('#zxr1').val()}
            if(crow[0].address !=''){
                $('.address').html(crow[0].address)
            }
            if(crow[0].mobile !=''){
                $('.mobile').html(crow[0].mobile)
            }
            if(crow[0].contacts !=''){
                $('.contacts').html(crow[0].contacts)
            }

//                    alert(value); //得到value
            layer.close(index);
        });

        $(".layui-layer-content").append("<br/><input type=\"text\" id= \"zxr1\" class=\"layui-input\" placeholder=\"联系人\"/>")
        $(".layui-layer-content").append("<br/><input type=\"text\" id= \"zxr2\" class=\"layui-input\" placeholder=\"手机号\"/>")
    })
</script>
<!---带扇形 不带footer->
